package ioperations;

import book.Book;
import book.bookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation {
    public void work(bookList BookList) {
        System.out.println("归还图书......");
        System.out.println("请输入你要归还的书");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int useSize = BookList.getUsesize();

        for (int i = 0; i < useSize; i++) {
            Book book = BookList.getBook(i);

            if (book.getName().equals(name)) {

                if(book.isBorrowed()){
                    book.setBorrowed(false);
                    System.out.println("归还成功！");
                    return;

                }
                System.out.println("没有你要归还的书！！");
                return;
            }
        }
    }
}
